home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Complementary Applications 2004 February / SGI IRIX 6.5 Complementary Applications 2004 February.iso / dist / cde.idb / usr / dt / share / examples / dtwidget / editor.c.z / editor.c
Encoding:
C/C++ Source or Header  |  2003-11-18  |  22.5 KB  |  886 lines

  1. /*
  2.  * editor.c
  3.  *
  4.  * Copyright 2000, Silicon Graphics, Inc.
  5.  * ALL RIGHTS RESERVED
  6.  * 
  7.  * UNPUBLISHED -- Rights reserved under the copyright laws of the United
  8.  * States.   Use of a copyright notice is precautionary only and does not
  9.  * imply publication or disclosure.
  10.  *
  11.  * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
  12.  * Use, duplication or disclosure by the Government is subject to restrictions
  13.  * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
  14.  * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
  15.  * in similar or successor clauses in the FAR, or the DOD or NASA FAR
  16.  * Supplement.  Contractor/manufacturer is Silicon Graphics, Inc.,
  17.  * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
  18.  *
  19.  * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
  20.  * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
  21.  * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
  22.  * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
  23.  * GRAPHICS, INC.
  24.  */
  25. /* $XConsortium: editor.c /main/cde1_maint/1 1995/07/17 16:45:58 drk $ */
  26. /*
  27.  *  (c) Copyright 1993, 1994 Hewlett-Packard Company
  28.  *  (c) Copyright 1993, 1994 International Business Machines Corp.
  29.  *  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  30.  *  (c) Copyright 1993, 1994 Novell, Inc.
  31.  */
  32.  
  33. /*
  34.  * editor.c
  35.  *
  36.  * A simple editor based on the DtEditor widget.
  37.  */
  38.  
  39. #include <stdio.h>
  40. #include <locale.h>
  41.  
  42. #include <Xm/XmAll.h>
  43.  
  44. #include <Dt/Editor.h>
  45.  
  46. /*
  47.  * Constants
  48.  */
  49.  
  50. #define ApplicationClass "Editor"
  51.  
  52. /*
  53.  * Types
  54.  */
  55.  
  56. typedef struct _AppData {
  57.     XtAppContext appContext;
  58.     Display    *display;
  59.     Widget top;
  60.     Widget mainWindow;
  61.     Widget menuBar;
  62.     Widget editor;
  63.     Widget messageTextF;
  64.     Widget fileSelectionBox;
  65.     Widget cutButton;
  66.     Widget copyButton;
  67.     Widget clearButton;
  68.     Widget deleteButton;
  69.     Widget deselectButton;
  70.     Widget cutPopupButton;
  71.     Widget copyPopupButton;
  72.     Boolean wordWrapOn;
  73.     Boolean statusLineOn;
  74.     Boolean overstrikeModeOn;
  75. } AppData;
  76.  
  77. /*
  78.  * Used to specify whether data is being loaded, inserted, or saved
  79.  * from the editor. Used used by the FSB and its callbacks.
  80.  */
  81.  
  82. typedef enum _LoadSaveType {
  83.         LOAD_DATA,
  84.         INSERT_DATA,
  85.         SAVE_DATA
  86. } LoadSaveType;
  87.  
  88. /*
  89.  * Data
  90.  */
  91.  
  92. static AppData ad;
  93.  
  94.  
  95. /*
  96.  * Functions
  97.  */
  98.  
  99. static void SetResizeHints(void);
  100. static void DisplayMessage(char *);
  101. static Widget CreateMenuBar(Widget);
  102. static Widget CreatePopupMenu(Widget);
  103. static Widget CreateEditor(Widget);
  104. static Widget CreateButton(Widget, String, char, XtCallbackProc, XtPointer);
  105. static Widget CreateToggle(Widget, String, char, XtCallbackProc, XtPointer, Boolean);
  106. static Widget CreateCascade(Widget, String, char, Widget);
  107. static void PopupHandler(Widget, XtPointer, XEvent*, Boolean*);
  108. static void SetSelectionState(Boolean);
  109.  
  110.  
  111. /*
  112.  * main
  113.  */
  114.  
  115. void main(int argc, char **argv)
  116. {
  117.     Arg    al[10];
  118.     int ac;
  119.  
  120.     XtSetLanguageProc( (XtAppContext)NULL, (XtLanguageProc)NULL,
  121.                    (XtPointer)NULL );
  122.  
  123.     /* Initialize the application's data */
  124.     ad.fileSelectionBox = (Widget) NULL;
  125.     ad.wordWrapOn = False;
  126.     ad.statusLineOn = False;
  127.     ad.overstrikeModeOn = False;
  128.  
  129.     /* Initialize the toolkit and open the display */
  130.     ad.top = XtAppInitialize(&ad.appContext, ApplicationClass, NULL, 0,
  131.                              &argc, argv, NULL, NULL, 0);
  132.     ad.display = XtDisplay(ad.top);
  133.  
  134.     /* Create MainWindow. */
  135.     ac = 0;
  136.     ad.mainWindow = (Widget) XmCreateMainWindow (ad.top, "main", al, ac);
  137.     XtManageChild (ad.mainWindow);
  138.  
  139.     /* Create MenuBar in MainWindow. */
  140.     ad.menuBar = CreateMenuBar(ad.mainWindow);
  141.     XtManageChild(ad.menuBar);
  142.  
  143.     /* Create editor widget in MainWindow. */
  144.     ad.editor = CreateEditor(ad.mainWindow);
  145.     XtManageChild(ad.editor);
  146.     ad.messageTextF = DtEditorGetMessageTextFieldID(ad.editor);
  147.  
  148.     /* Create the editor popup menu */
  149.     CreatePopupMenu(ad.editor);
  150.  
  151.     /* Set the main window widgets. */
  152.     XmMainWindowSetAreas(ad.mainWindow, ad.menuBar, NULL, NULL, NULL, ad.editor);
  153.  
  154.     /* Realize toplevel widget */
  155.     XtRealizeWidget (ad.top);
  156.  
  157.     /* Set the resize increment and minimum window size properties. */
  158.     SetResizeHints();
  159.  
  160.     /* Set up menu buttons dependent on selection */
  161.     SetSelectionState(False);
  162.  
  163.     XtAppMainLoop(ad.appContext);
  164.  
  165.  
  166. /************************************************************************
  167.  *
  168.  * Callbacks
  169.  *
  170.  ************************************************************************/
  171.  
  172. /*
  173.  * File menu callbacks
  174.  */
  175.  
  176. static void ResetEditorCb(Widget w, XtPointer cd, XtPointer cb)
  177. {
  178.    DtEditorReset(ad.editor);
  179. }
  180.  
  181. static void OpenFileCb( Widget w, XtPointer cd, XtPointer cb)
  182. {
  183.    DtEditorErrorCode error;
  184.    XmFileSelectionBoxCallbackStruct *fcb = (XmFileSelectionBoxCallbackStruct *) cb;
  185.    LoadSaveType LoadSaveFlag = (LoadSaveType)cd;
  186.    char *name = (char *) XtMalloc( sizeof(char) * fcb->length + 1 );
  187.  
  188.    name[0] ='\0';
  189.  
  190.    /*
  191.     *  Get the name of the file & pass it to the editor widget
  192.     */
  193.  
  194.    XmStringGetLtoR(fcb->value, XmFONTLIST_DEFAULT_TAG, &name);
  195.  
  196.    /*
  197.     * Load or insert the file, as specified
  198.     */
  199.    if ( LoadSaveFlag == LOAD_DATA )
  200.      error = DtEditorSetContentsFromFile(ad.editor, name); 
  201.    else
  202.      error = DtEditorInsertFromFile(ad.editor, name); 
  203.  
  204.    switch (error)
  205.    {
  206.      case DtEDITOR_NO_ERRORS:
  207.      {
  208.        DisplayMessage("File loaded");
  209.        break;
  210.      }
  211.      case DtEDITOR_NULLS_REMOVED:
  212.      {
  213.     DisplayMessage( "All embedded null characters removed from the file" );
  214.     break;
  215.      }
  216.      case DtEDITOR_READ_ONLY_FILE:
  217.      {
  218.        DisplayMessage( "The file is write protected" );
  219.        break;
  220.      }
  221.      case DtEDITOR_NONEXISTENT_FILE:
  222.      {
  223.        DisplayMessage( "Could not find file" );
  224.        break;
  225.      }
  226.      case DtEDITOR_DIRECTORY:
  227.      {
  228.        DisplayMessage( "The name given is a directory" );
  229.        break;
  230.      }
  231.      case DtEDITOR_CHAR_SPECIAL_FILE:
  232.      {
  233.        DisplayMessage( "The name given is a character special device" );
  234.        break;
  235.      }
  236.      case DtEDITOR_BLOCK_MODE_FILE:
  237.      {
  238.        DisplayMessage( "The name given is a block mode device");
  239.        break;
  240.      }
  241.      case DtEDITOR_INSUFFICIENT_MEMORY:
  242.      {
  243.        DisplayMessage( "Not enough available memory to load file");
  244.        break;
  245.      }
  246.      case DtEDITOR_UNREADABLE_FILE:
  247.      default:
  248.      {
  249.        DisplayMessage( "Could not read the file" );
  250.        break;
  251.      }
  252.    }
  253.  
  254.    /*
  255.     * Remove the OK callback so it can be added again with a new value for 
  256.     * the LoadSaveFlag flag.
  257.     */
  258.    XtRemoveCallback(w, XmNokCallback, OpenFileCb, cd);
  259.  
  260.    /*
  261.     * Remove the FSB dialog & clean up
  262.     */
  263.    XtUnmanageChild(w);
  264.    XtFree (name);
  265. }
  266.  
  267.  
  268. static void SaveAsFileCb(Widget w, XtPointer cd, XtPointer cb)
  269. {
  270.    DtEditorContentRec    cr;
  271.    DtEditorErrorCode    error;
  272.    Boolean        overWrite = False,
  273.             hardCarriageReturns = True,
  274.             markContentsAsSaved = True;
  275.    XmFileSelectionBoxCallbackStruct *fcb = (XmFileSelectionBoxCallbackStruct *)cb;
  276.    LoadSaveType LoadSaveFlag = (LoadSaveType) cd;
  277.  
  278.    char *name = XtMalloc(sizeof(char) * fcb->length + 1 );
  279.    name[0] ='\0';
  280.    XmStringGetLtoR(fcb->value, XmFONTLIST_DEFAULT_TAG, &name);
  281.  
  282.    /*
  283.     * Ask the widget to save its contents to the named file.
  284.     */
  285.  
  286.    error = DtEditorSaveContentsToFile(ad.editor, name, overWrite,
  287.         hardCarriageReturns, markContentsAsSaved); 
  288.  
  289.    switch(error)
  290.    {
  291.      case DtEDITOR_NO_ERRORS:
  292.      {
  293.        DisplayMessage( "The file has been saved" );
  294.        break;
  295.      }
  296.      case DtEDITOR_UNWRITABLE_FILE:
  297.      {
  298.        DisplayMessage( "The file is read only" ); 
  299.        break;
  300.      }
  301.      case DtEDITOR_WRITABLE_FILE:
  302.      {
  303.        DisplayMessage( "File not saved, it already exists" ); 
  304.        break;
  305.      }
  306.      case DtEDITOR_DIRECTORY:
  307.      {
  308.        DisplayMessage( "The name given is a directory" );
  309.        break;
  310.      }
  311.      case DtEDITOR_CHAR_SPECIAL_FILE:
  312.      {
  313.        DisplayMessage( "The name given is a character special device" );
  314.        break;
  315.      }
  316.      case DtEDITOR_BLOCK_MODE_FILE:
  317.      {
  318.        DisplayMessage( "The name given is a block mode device");
  319.        break;
  320.      }
  321.      case DtEDITOR_SAVE_FAILED:
  322.      default:
  323.      {
  324.        DisplayMessage( "Could not save the file.  Check disc space" );
  325.        break;
  326.      }
  327.    }
  328.  
  329.    /*
  330.     * Remove the OK callback so it can be added again with a new value for 
  331.     * the LoadSaveFlag flag.
  332.     */
  333.    XtRemoveCallback(w, XmNokCallback, SaveAsFileCb, cd);
  334.  
  335.    /*
  336.     * Remove the FSB dialog & clean up
  337.     */
  338.    XtUnmanageChild( w );
  339.    XtFree (name);
  340.  
  341. }
  342.  
  343.  
  344. static void CancelOpenCb(Widget w, XtPointer cd, XtPointer cb)
  345. {
  346.    /* Remove the OK callback so it can be added again with a new value for 
  347.     * the LoadSaveFlag flag.
  348.     */
  349.    XtRemoveCallback(w, XmNokCallback, OpenFileCb, cd);
  350.  
  351.    /* Remove the FSB dialog & clean up */
  352.    XtUnmanageChild(w);
  353. }
  354.  
  355.  
  356. static void DisplayFsbCb(Widget w, XtPointer cd, XtPointer cb)
  357. {
  358.   Arg al[10];
  359.   int ac;
  360.   XmString tmpStr1, tmpStr2;
  361.  
  362.   LoadSaveType LoadSaveFlag = (LoadSaveType) cd;
  363.  
  364.   /* Create the FSB, if we need to */
  365.  
  366.   if (ad.fileSelectionBox == (Widget) NULL)
  367.   {
  368.      ac = 0;
  369.      ad.fileSelectionBox = XmCreateFileSelectionDialog(ad.mainWindow,
  370.                             "file_sel_dlg",
  371.                             al, ac);
  372.      XtAddCallback(ad.fileSelectionBox, XmNcancelCallback, CancelOpenCb,    
  373.                         (XtPointer)LoadSaveFlag);
  374.  
  375.   }
  376.  
  377.   /*
  378.    * Set FSB title & label depending up whether loading, inserting, or
  379.    * saving a container.
  380.    */
  381.   switch ( LoadSaveFlag )
  382.   {
  383.     case LOAD_DATA:
  384.     {
  385.       tmpStr1 = XmStringCreateLocalized("Open a File");
  386.       tmpStr2 = XmStringCreateLocalized("File to open");
  387.  
  388.       /*
  389.        * Add the OK callback so the curent value of the LoadSaveFlag 
  390.        * flag is passed in.
  391.        */
  392.       XtAddCallback(ad.fileSelectionBox, XmNokCallback, OpenFileCb,
  393.                         (XtPointer)LoadSaveFlag);
  394.       break;
  395.     }
  396.  
  397.     case INSERT_DATA:
  398.     {
  399.       tmpStr1 = XmStringCreateLocalized("Include a File");
  400.       tmpStr2 = XmStringCreateLocalized("File to include");
  401.  
  402.       /*
  403.        * Add the OK callback so the curent value of the LoadSaveFlag 
  404.        * flag is passed in.
  405.        */
  406.       XtAddCallback(ad.fileSelectionBox, XmNokCallback, OpenFileCb,
  407.                         (XtPointer)LoadSaveFlag);
  408.       break;
  409.     }
  410.  
  411.     case SAVE_DATA:
  412.     {
  413.       tmpStr1 = XmStringCreateLocalized("Save to File");
  414.       tmpStr2 = XmStringCreateLocalized("Save to file");
  415.  
  416.       /*
  417.        * Add the OK callback so the save as callback is called.
  418.        */
  419.       XtAddCallback(ad.fileSelectionBox, XmNokCallback, SaveAsFileCb,
  420.                         (XtPointer)LoadSaveFlag);
  421.       break;
  422.     }
  423.  
  424.     default:
  425.     {
  426.     break;
  427.     }
  428.   }
  429.  
  430.   XtVaSetValues(ad.fileSelectionBox,
  431.     XmNdialogTitle, tmpStr1,
  432.       XmNselectionLabelString, tmpStr1,
  433.     NULL);
  434.  
  435.   XmStringFree(tmpStr1);
  436.   XmStringFree(tmpStr2);
  437.  
  438.   /* Display the FSB */
  439.  
  440.   XtManageChild (ad.fileSelectionBox);
  441. }
  442.  
  443.  
  444. static void ExitCb(Widget w, XtPointer cd, XtPointer cb)
  445. {
  446.     exit(0);
  447. }
  448.  
  449. /***************************************************** 
  450.  *
  451.  * Edit menu callbacks
  452.  *
  453.  */
  454.  
  455. static void UndoCb(Widget w, XtPointer cd, XtPointer cb)
  456. {
  457.     DtEditorUndoEdit(ad.editor); 
  458. }
  459.  
  460. static void CutCb(Widget w, XtPointer cd, XtPointer cb)
  461. {
  462.     DtEditorCutToClipboard(ad.editor); 
  463. }
  464.  
  465. static void CopyCb(Widget w, XtPointer cd, XtPointer cb)
  466. {
  467.     DtEditorCopyToClipboard(ad.editor); 
  468. }
  469.  
  470. static void PasteCb(Widget w, XtPointer cd, XtPointer cb)
  471. {
  472.     DtEditorPasteFromClipboard(ad.editor); 
  473. }
  474.  
  475. static void ClearCb(Widget w, XtPointer cd, XtPointer cb)
  476. {
  477.     DtEditorClearSelection(ad.editor);
  478. }
  479.  
  480. static void DeleteCb(Widget w, XtPointer cd, XtPointer cb)
  481. {
  482.     DtEditorDeleteSelection(ad.editor);
  483. }
  484.  
  485. static void SelectAllCb(Widget w, XtPointer cd, XtPointer cb)
  486. {
  487.     DtEditorSelectAll(ad.editor); 
  488. }
  489.  
  490. static void DeselectCb(Widget w, XtPointer cd, XtPointer cb)
  491. {
  492.     DtEditorDeselect(ad.editor); 
  493. }
  494.  
  495. static void FindCb(Widget w, XtPointer cd, XtPointer cb)
  496. {
  497.     DtEditorInvokeFindChangeDialog(ad.editor); 
  498. }
  499.  
  500. static void SpellCb(Widget w, XtPointer cd, XtPointer cb)
  501. {
  502.     DtEditorInvokeSpellDialog(ad.editor); 
  503. }
  504.  
  505. /***************************************************** 
  506.  *
  507.  * Format menu callbacks
  508.  *
  509.  */
  510.  
  511. static void FormatAllCb(Widget w, XtPointer cd, XtPointer cb)
  512. {
  513.    DtEditorFormat(ad.editor, (DtEditorFormatSettings *) NULL, 
  514.           DtEDITOR_FORMAT_ALL); 
  515. }
  516.  
  517. static void FormatParaCb(Widget w, XtPointer cd, XtPointer cb)
  518. {
  519.    DtEditorFormat(ad.editor, (DtEditorFormatSettings *) NULL, 
  520.           DtEDITOR_FORMAT_PARAGRAPH); 
  521. }
  522.  
  523. static void InvokeFormatDlgCb(Widget w, XtPointer cd, XtPointer cb)
  524. {
  525.     DtEditorInvokeFormatDialog(ad.editor); 
  526. }
  527.  
  528. /***************************************************** 
  529.  *
  530.  * Options menu callbacks
  531.  *
  532.  */
  533.  
  534. static void OverstrikeCb(Widget w, XtPointer cd, XtPointer cb)
  535. {
  536.     ad.overstrikeModeOn = ad.overstrikeModeOn ? False : True;
  537.     XtVaSetValues(ad.editor, DtNoverstrike, ad.overstrikeModeOn, NULL); 
  538. }
  539.  
  540. static void StatusLineCb(Widget w, XtPointer cd, XtPointer cb)
  541. {
  542.     ad.statusLineOn = ad.statusLineOn ? False : True;
  543.     XtVaSetValues(ad.editor, DtNshowStatusLine, ad.statusLineOn, NULL); 
  544.  
  545.     /* Reset the resize increment and minimum window size properties. */
  546.    SetResizeHints();
  547.  
  548. }
  549.  
  550. static void WordWrapCb(Widget w, XtPointer cd, XtPointer cb)
  551. {
  552.     ad.wordWrapOn = ad.wordWrapOn ? False : True;
  553.     XtVaSetValues(ad.editor, DtNwordWrap, ad.wordWrapOn, NULL); 
  554. }
  555.  
  556. /***************************************************** 
  557.  *
  558.  * Editor callbacks
  559.  *
  560.  */
  561.  
  562. static void HelpCb(Widget w, XtPointer cd, XtPointer cb)
  563. {
  564.   DtEditorHelpCallbackStruct *ecb = (DtEditorHelpCallbackStruct *)cb;
  565.  
  566.   DisplayMessage( "Received a request for help");
  567. }
  568.  
  569. static void TextSelectedCb(Widget w, XtPointer cd, XtPointer cb)
  570. {
  571.     SetSelectionState(True);
  572. }
  573.  
  574. static void TextUnselectedCb(Widget w, XtPointer cd, XtPointer cb)
  575. {
  576.     SetSelectionState(False);
  577. }
  578.  
  579. static void SetSelectionState(Boolean state)
  580. {
  581.     XtSetSensitive(ad.cutButton, state);
  582.     XtSetSensitive(ad.copyButton, state);
  583.     XtSetSensitive(ad.deleteButton, state);
  584.     XtSetSensitive(ad.clearButton, state);
  585.     XtSetSensitive(ad.deselectButton, state);
  586.     XtSetSensitive(ad.cutPopupButton, state);
  587.     XtSetSensitive(ad.copyPopupButton, state);
  588. }
  589.  
  590. /************************************************************************
  591.  *
  592.  * PROCEDURES 
  593.  *
  594.  ************************************************************************/
  595.  
  596. /************************************************************************
  597.  *
  598.  * SetResizeHints - Set the resize increment properties
  599.  *
  600.  */
  601.  
  602. static void SetResizeHints(void)
  603. {
  604.    XSizeHints  sh;
  605.    Dimension MBheight;
  606.  
  607.    DtEditorGetSizeHints(ad.editor, &sh);
  608.  
  609.    /*
  610.     * Add Menu Bar height to the height of the Editor widget
  611.     */
  612.    XtVaGetValues( ad.menuBar, XmNheight, &MBheight, NULL);
  613.    sh.min_height += MBheight;
  614.    sh.base_height += MBheight;
  615.  
  616.    XSetWMSizeHints(ad.display, XtWindow(ad.top), &sh, XA_WM_NORMAL_HINTS);
  617. }
  618.  
  619. /************************************************************************
  620.  *
  621.  * DisplayMessage - Display message in DtEditor's message area
  622.  *
  623.  */
  624.  
  625. static void DisplayMessage(char *message)
  626. {
  627.     XmTextFieldSetString(ad.messageTextF, message);
  628. }
  629.  
  630. /************************************************************************
  631.  *
  632.  * CreateFileMenu - Create the File pulldown menu
  633.  *
  634.  */
  635.  
  636. static Widget CreateFileMenu(Widget menuBar)
  637. {
  638.     Widget fileMenu; 
  639.  
  640.     fileMenu = (Widget) XmCreatePulldownMenu (menuBar, "fileMenu", NULL, 0);
  641.     CreateCascade(menuBar, "File", 'F', fileMenu);
  642.     CreateButton(fileMenu, "New", 'N', ResetEditorCb, NULL);
  643.     CreateButton(fileMenu, "Open...", 'O', DisplayFsbCb, (XtPointer)LOAD_DATA);
  644.     CreateButton(fileMenu, "Include...", 'I', DisplayFsbCb,
  645.                             (XtPointer)INSERT_DATA);
  646.     XtManageChild(XmCreateSeparatorGadget(fileMenu, "sep1", NULL, 0));
  647.     CreateButton(fileMenu, "Save As...", 'A', DisplayFsbCb, (XtPointer)SAVE_DATA);
  648.     XtManageChild(XmCreateSeparatorGadget(fileMenu, "sep2", NULL, 0));
  649.     CreateButton(fileMenu, "Exit", 'x', ExitCb, NULL);
  650.  
  651.     return (fileMenu);
  652. }
  653.  
  654. /************************************************************************
  655.  *
  656.  * CreateEditMenu - Create the Edit pulldown menu
  657.  *
  658.  */
  659.  
  660. static Widget CreateEditMenu(Widget menuBar)
  661. {
  662.     Widget editMenu;
  663.  
  664.     editMenu = XmCreatePulldownMenu (menuBar, "editMenu", NULL, 0);
  665.  
  666.     CreateCascade(menuBar, "Edit", 'E', editMenu);
  667.  
  668.     CreateButton(editMenu, "Undo", 'U', UndoCb, NULL);
  669.     XtManageChild(XmCreateSeparatorGadget(editMenu, "sep1", NULL, 0));
  670.     ad.cutButton = CreateButton(editMenu, "Cut", 't', CutCb, NULL);
  671.     ad.copyButton = CreateButton(editMenu, "Copy", 'C', CopyCb, NULL);
  672.     CreateButton(editMenu, "Paste", 'P', PasteCb, NULL);
  673.     ad.clearButton = CreateButton(editMenu, "Clear", 'e', ClearCb, NULL);
  674.     ad.deleteButton = CreateButton(editMenu, "Delete", 't', DeleteCb, NULL);
  675.     CreateButton(editMenu, "Select All", 'S', SelectAllCb, NULL);
  676.     ad.deselectButton = CreateButton(editMenu, "Deselect", 'D', DeselectCb, NULL);
  677.     XtManageChild(XmCreateSeparatorGadget(editMenu, "sep2", NULL, 0));
  678.     CreateButton(editMenu, "Find/Change...", 'F', FindCb, (XtPointer)ad.editor);
  679.     CreateButton(editMenu, "Check Spelling...", 'p', SpellCb, (XtPointer)ad.editor);
  680.  
  681.     return (editMenu);
  682. }
  683.  
  684.  
  685. /************************************************************************
  686.  *
  687.  * CreateFormatMenu - Create the FormatEdit pulldown menu
  688.  *
  689.  */
  690.  
  691. static Widget CreateFormatMenu(Widget menuBar)
  692. {
  693.     Widget formatMenu;
  694.  
  695.     formatMenu = XmCreatePulldownMenu (menuBar, "formatMenu", NULL, 0);
  696.  
  697.     CreateCascade(menuBar, "Format", 'r', formatMenu);
  698.  
  699.     CreateButton(formatMenu, "Settings...", 'S', InvokeFormatDlgCb, NULL);
  700.     CreateButton(formatMenu, "All", 'A', FormatAllCb, NULL);
  701.     CreateButton(formatMenu, "Paragraph", 'P', FormatParaCb, NULL);
  702.  
  703.     return (formatMenu);
  704. }
  705.  
  706. /************************************************************************
  707.  *
  708.  * CreateOptionsMenu - Create the Options pulldown menu
  709.  *
  710.  */
  711.  
  712. static Widget CreateOptionsMenu(Widget menuBar)
  713. {
  714.     Widget optionsMenu;
  715.  
  716.     optionsMenu = XmCreatePulldownMenu (menuBar, "optionsMenu", NULL, 0);
  717.  
  718.     CreateCascade(menuBar, "Options", 'O', optionsMenu);
  719.  
  720.     CreateToggle(optionsMenu, "Overstrike", 'O', OverstrikeCb, NULL, ad.overstrikeModeOn);
  721.     CreateToggle(optionsMenu, "Word Wrap", 'W', WordWrapCb, NULL,ad.wordWrapOn);
  722.     XtManageChild(XmCreateSeparatorGadget(optionsMenu, "sep1", NULL, 0));
  723.     CreateToggle(optionsMenu, "Status Line", 'S', StatusLineCb, NULL, ad.statusLineOn);
  724.  
  725.     return (optionsMenu);
  726. }
  727.  
  728. /*
  729.  * CreatePopupMenu - Create popup menu in editor window
  730.  */
  731.  
  732. static Widget CreatePopupMenu(Widget parent)
  733.     Widget popupMenu;
  734.     Widget fileMenu;
  735.     Widget editMenu;
  736.  
  737.     popupMenu = XmCreatePopupMenu(parent, "popupMenu", NULL, 0);
  738.  
  739.     XtAddEventHandler(parent, ButtonPressMask, False, PopupHandler,
  740.                             (XtPointer)popupMenu);
  741.  
  742.     fileMenu = XmCreatePulldownMenu (popupMenu, "fileMenu", NULL, 0);
  743.     CreateCascade(popupMenu, "File", 'F', fileMenu);
  744.     CreateButton(fileMenu, "Open...", 'O', DisplayFsbCb, (XtPointer)LOAD_DATA);
  745.     CreateButton(fileMenu, "Include...", 'I', DisplayFsbCb,
  746.                             (XtPointer)INSERT_DATA);
  747.     CreateButton(fileMenu, "Save As...", 'A', DisplayFsbCb, (XtPointer)SAVE_DATA);
  748.     CreateButton(fileMenu, "New", 'N', ResetEditorCb, NULL);
  749.  
  750.     editMenu = XmCreatePulldownMenu (popupMenu, "editMenu", NULL, 0);
  751.     CreateCascade(popupMenu, "Edit", 'E', editMenu);
  752.     CreateButton(editMenu, "Undo", 'U', UndoCb, (XtPointer)LOAD_DATA);
  753.     ad.cutPopupButton = CreateButton(editMenu, "Cut", 't', CutCb, NULL);
  754.     ad.copyPopupButton = CreateButton(editMenu, "Copy", 'C', CopyCb, NULL);
  755.     CreateButton(editMenu, "Paste", 'P', PasteCb, NULL);
  756.  
  757.     CreateButton(popupMenu, "Find/Change...", 'F', FindCb, (XtPointer)ad.editor);
  758.  
  759.     return (popupMenu);
  760. }
  761.  
  762. static void PopupHandler(Widget w, XtPointer cd, XEvent *event, Boolean *ctd)
  763. {
  764.     if (((XButtonEvent *)event)->button != Button3) return;
  765.  
  766.     XmMenuPosition((Widget)cd, (XButtonEvent *)event);
  767.     XtManageChild ((Widget)cd);
  768. }
  769.  
  770.  
  771. /*
  772.  * CreateMenuBar - Create MenuBar in MainWindow
  773.  */
  774.  
  775. static Widget CreateMenuBar(Widget parent)
  776.     Widget menuBar;
  777.  
  778.     menuBar = XmCreateMenuBar(parent, "menuBar", NULL, 0);
  779.  
  780.     CreateFileMenu(menuBar);
  781.     CreateEditMenu(menuBar);
  782.     CreateFormatMenu(menuBar);
  783.     CreateOptionsMenu(menuBar);
  784.  
  785.     return (menuBar);
  786. }
  787.  
  788.  
  789. /*
  790.  * CreateEditor - Create the editor widget
  791.  */
  792.  
  793. static Widget CreateEditor(Widget parent)
  794. {
  795.     Widget w;
  796.     Arg al[10];
  797.     int ac;
  798.  
  799.     /* create editor widget */
  800.  
  801.     ac = 0;
  802.     XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
  803.     XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
  804.     XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
  805.     XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
  806.     XtSetArg(al[ac], DtNrows, 40); ac++;
  807.     XtSetArg(al[ac], DtNcolumns, 80); ac++;
  808.     w = DtCreateEditor(parent, "editor", al, ac);
  809.  
  810.     /* Add callbacks */
  811.  
  812.     XtAddCallback(w, DtNtextSelectCallback, TextSelectedCb, (XtPointer) w);
  813.     XtAddCallback(w, DtNtextDeselectCallback, TextUnselectedCb, (XtPointer) w);
  814.     XtAddCallback(w, XmNhelpCallback, HelpCb, NULL);
  815.  
  816.     return(w);
  817. }
  818.  
  819. static Widget CreateButton(Widget parent, String label, char mnemonic, XtCallbackProc callback, XtPointer callData)
  820. {
  821.     Widget button;
  822.     XmString labelString;
  823.     Arg al[10];
  824.     int ac;
  825.  
  826.     labelString = XmStringCreateLocalized(label);
  827.  
  828.     ac = 0;
  829.     XtSetArg(al[ac], XmNlabelString, labelString); ac++;
  830.     XtSetArg(al[ac], XmNmnemonic, mnemonic); ac++;
  831.     button = XmCreatePushButtonGadget(parent, label, al, ac);
  832.     XtAddCallback(button, XmNactivateCallback, callback, callData);
  833.     XtManageChild(button);
  834.  
  835.     XmStringFree(labelString);
  836.  
  837.     return(button);
  838.  
  839. static Widget CreateToggle(Widget parent, String label, char mnemonic, XtCallbackProc callback, XtPointer callData, Boolean value)
  840. {
  841.     Widget button;
  842.     XmString labelString;
  843.     Arg al[10];
  844.     int ac;
  845.  
  846.     labelString = XmStringCreateLocalized(label);
  847.  
  848.     ac = 0;
  849.     XtSetArg(al[ac], XmNlabelString, labelString); ac++;
  850.     XtSetArg(al[ac], XmNmnemonic, mnemonic); ac++;
  851.     XtSetArg(al[ac], XmNvisibleWhenOff, True); ac++;
  852.     XtSetArg(al[ac], XmNset, value); ac++;
  853.     button = XmCreateToggleButtonGadget(parent, label, al, ac);
  854.     XtAddCallback(button, XmNvalueChangedCallback, callback, callData);
  855.     XtManageChild(button);
  856.  
  857.     XmStringFree(labelString);
  858.  
  859.     return(button);
  860.  
  861. static Widget CreateCascade(Widget parent, String label, char mnemonic, Widget subMenu)
  862. {
  863.     Widget button;
  864.     XmString labelString;
  865.     Arg al[10];
  866.     int ac;
  867.  
  868.     labelString = XmStringCreateLocalized(label);
  869.  
  870.     ac = 0;
  871.     XtSetArg(al[ac], XmNlabelString, labelString); ac++;
  872.     XtSetArg(al[ac], XmNsubMenuId, subMenu); ac++;
  873.     XtSetArg(al[ac], XmNmnemonic, mnemonic); ac++;
  874.     button = XmCreateCascadeButtonGadget(parent, label, al, ac);
  875.     XtManageChild(button);
  876.  
  877.     XmStringFree(labelString);
  878.  
  879.     return(button);
  880.